package edu.whu.controller;

import edu.whu.bean.Product;
import edu.whu.service.ProductService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {
    ProductService service = new ProductService();

    @GetMapping("/select")
    public edu.whu.bean.Product selectOne(Integer id){
        return service.selectById(id);
    }

    @GetMapping("/select/all")
    public List<edu.whu.bean.Product> selectAll(){
        return service.selectAll();
    }

    @GetMapping("/save")
    public Product insert(Integer id,String name,Double price,Integer count,Integer sales){
        Product product = new Product(id,name,price,count,sales);
        service.save(product);
        return product;
    }

    @GetMapping("/delete")
    public int delete(Integer id){
        service.deleteById(id);
        return id;
    }

    @GetMapping("/clear")
    public int clear(){
        return service.clear();
    }
}











